<?php

class CalendarController extends FormController
{

  protected $table = 'calendar';

  protected $pk = 'cal_id';

  protected function initialize()
  {
    parent::initialize();

    $this->Form->addElement(new FormElement_Text('cal_title', 'Title'), Form::ACTION_ALL | Form::ACTION_CALENDAR);
    $this->Form->addElement(new FormElement_DateTime('cal_start', 'Start Date'));
    $this->Form->addElement(new formelement_Boolean('cal_allday', 'All day event'));
    $this->Form->addElement(new FormElement_DateTime('cal_end', 'End Date'));
  }

  protected function indexAction()
  {
    return $this->response->redirect(array('/admin/calendar', array('action' => 'calendar')));
  }

  protected function calendarAction()
  {
    try {
      $this->Form->execute(Form::ACTION_CALENDAR);
    }
    catch (FormNoSuchActionException $e) {
      $this->response->redirect('/admin');
    }
    catch (ValidationException $e) {
      s::getInstance()->warnings($e->getErrors());
    }

    return $this->Form->render(Form::ACTION_CALENDAR);
  }

}
